import {
  BadRequestException,
  Body,
  Controller,
  Delete,
  Get,
  HttpStatus,
  InternalServerErrorException,
  NotFoundException,
  Param,
  Post,
  Query,
  Res,
} from '@nestjs/common';
import { ProjectService } from './project.service';
import { CreateProjectDto } from './dto/create-project.dto';

@Controller('project')
export class ProjectController {

  constructor(private projectService: ProjectService) {
  }

  @Get()
  findAll(@Query('name') name) {
    return this.projectService.findAll(name);
  }

  @Post()
  create(@Body() body: CreateProjectDto) {
    return this.projectService.create(body);
  }

  @Get(':id')
  async findOne(@Param('id') id) {
    const project = await this.projectService.findOneById(id);
    if (project) {
      return project;
    } else {
      throw new NotFoundException(`未找到id为${id}的项目`);
    }
  }

  @Delete(':id')
  delete(@Param('id') id: number) {
    return this.projectService.deleteOne(id);
  }

  @Delete()
  async deleteAll() {
      return await this.projectService.deleteAll();
  }
}
